package com.budwk.app.sqfwV2.enums.dayingRoad;

import com.budwk.app.sqfwV2.dto.dto.centuryCity.SafeCheckTaskParamDataDTO;
import com.budwk.app.sqfwV2.dto.dto.dayingRoad.ProblemBaseVo;
import com.budwk.app.sqfwV2.enums.RectificateTimeEnum;
import lombok.Getter;

import java.util.*;

/**
 * 重点安全排查行业31个问题默认值
 */
@Getter
public enum KeySafetyIndustriesEnum {

    ONE("1","isThereWeldingOperation", "false", "是否存在违规动火动焊作业"), //1
    TWO("2","areHotOperatorsWork", "true", "动火动焊作业人员是否持证上岗"),//2
    THREE("3","duringTheConstruction", "true", "施工期间是否落实现场看护人员、提前清理可燃杂物和落实安全防护措施"),//3
    FORE("4","whetherFlamExplosive", "false", "是否违规存放、使用易燃易爆危险品"),//4
    FIVE("5","mproperIllegalDistribution", "false", "配电箱（柜）、电缆井电线是否存在连接不规范， 违规存放可燃易燃物"),//5
    SIX("6","areAnyWiresMate", "false", "电线电缆是否存在未穿管保护，直接穿越易燃可燃材料，开关、插座直接安装在易燃可燃材料上"),//6
    SEVEN("7","islegalUseElectrica", "false", "是否违规使用未经产品质量认证的大功率电器或移动插排"),//7
    EIGHT("8","areOxygenNnon", "false", "医院、养老院的制氧站、氧气瓶间是否违规使用非防爆电器设备、使用锂离子电池的医疗设备、轮椅未在指定安全区域充电"),//8
    NINE("9","whetherElectricParked", "false", "电动自行车（蓄电池）是否违规在室内停放或充电"),//9
    TEN("10","isIegalUseSuch", "false", "人员密集场所是否违规使用聚丙烯、聚乙烯、聚氨酯、聚苯乙烯等材质的易燃可燃材料尤其是塑料绿植，进行装饰装修"),//10
    ELEVEN("11","isAnyConstructPlate", "false", "是否存在违章搭建易燃可燃材料夹芯彩钢板建筑"),//11
    TWELVE("12","doesMixedDangero", "false", "混合生产经营场所是否违规储存、使用易燃易爆危险品"),//12
    THIRTEEN("13","doesGatherPlace", "false", "公众聚集场所是否违规使用易燃、可燃材料装修"),//13
    FORETEEN("14","isThereAnyBlockage", "false", "是否存在占用、堵塞、封闭疏散通道、安全出口、消防车道和登高车操作场地"),//14
    FIVETEEN("15","areObstaclesDoorsFfire", "false", "是否在人员密集场所的门窗上设置影响逃生和灭火救援的障碍物"),//15
    SIXTEEN("16","doesHomePatients", "false", "医院、养老院是否将失能和行动不便患者安排在建筑较低楼层，是否在通道、楼梯间增加床位，影响人员疏散"),//16
    SEVENTEEN("17","doorsFireAre", "false", "防火门、防火卷帘、防火墙等损坏严重，不具备防火分隔功能"),//17
    EIGHTTEEN("18","isFireproofWells", "true", "电缆井、管道井等防火封堵是否严密"),//18
    NINETEEN("19","isMAixedVenues", "false", "混合生产经营场所内是否存在违规设置员工宿舍"),//19
    TWENTY("20","isFireWater", "false", "是否存在未按要求设置室内消火栓系统，或水压、水量不能满足灭火需求"),//20
    TWENTYONE("21","isAnysetAlarm", "false", "是否存在未按要求设置火灾自动报警、自动喷水灭火、气体灭火、防排烟等设施，或消防设施系统损坏瘫痪无法正常使用，不具备防灭火功能"),//21
    TWENTYTWO("22","isThereSignAgenc", "false", "设置自动消防设施的，是否存在未按要求与具备资质的消防服务机构签订消防设施维护保养合同"),//22
    TWENTYTHREE("23","isClearThatPerson", "true", "是否明确法定代表人为消防安全责任人、明确分管领导为消防安全管理人"),//23
    TWENTYFORE("24","isHotSystemDuty", "true", "是否严格落实动火施工审批制度、夜间值班制度"),//24
    TWENTYFIVE("25","whetherSafetyStaff", "true", "是否开展全员消防培训、疏散演练"),//25
    TWENTYSIX("26","isThereDutyRoom", "true", "消防控制室是否有人员值班"),//26
    TWENTYSEVEN("27","isDutyRoomWork", "true", "消防控制室值班人员是否持证上岗"),//27
    TWENTYEIGHT("28","doHaveWel", "true", "企业员工是否掌握自身消防工作职责和本场所火灾风险和防火措施"),//28
    TWENTYNINE("29","isWarnCarriedOut", "true", "是否开展火灾警示教育"),//29
    TWENTYTEN("30","isHaveMicroFireStations", "true", "是否按要求建立微型消防站或明确初期火灾扑救力量"),//30
    THIRTYONE("31","isHaveFireActual", "true", "是否结合本单位实际制定可操作的灭火和应急疏散预案"); // 31

    private final String number;

    private final String code;

    private final String defaultValue;

    private final String desc;

    KeySafetyIndustriesEnum(String number, String code, String defaultValue, String desc) {
        this.number = number;
        this.code = code;
        this.defaultValue = defaultValue;
        this.desc = desc;
    }

    /**
     *
     */
    public static Map<String, SafeCheckTaskParamDataDTO> getProblemValues(List<SafeCheckTaskParamDataDTO> keySafes) {
        Map<String, SafeCheckTaskParamDataDTO> map = new LinkedHashMap<>();
        for (SafeCheckTaskParamDataDTO keySafe : keySafes) {
            map.put(keySafe.getFields(), keySafe);
        }
        return map;
    }

    /**
     * 获取问题编号
     */
    public static KeySafetyIndustriesEnum getEnumByCode(String code) {
        Optional<KeySafetyIndustriesEnum> optional = Arrays.stream(values()).filter(e -> e.getCode().equals(code)).findFirst();
        return optional.orElse(null);
    }

    /**
     * 设置默认值 并返回对象
     */
    public static List<SafeCheckTaskParamDataDTO> getAllDefaults() {
        List<SafeCheckTaskParamDataDTO> list = new ArrayList<>();
        Arrays.stream(values()).forEach(e -> list.add(initData(e)));
        return list;
    }

    /**
     * 获取问题默认值 组装ProblemBaseVo对象
     */
    public static List<ProblemBaseVo> getProblemBaseVoDefaults() {
        List<ProblemBaseVo> list = new ArrayList<>();
        Arrays.stream(values()).forEach(e -> {
            ProblemBaseVo vo = new ProblemBaseVo();
            list.add(vo.setCode(e.getCode()).setDefaultValue(e.getDefaultValue()).setDesc(e.getDesc()).setNumber(e.getNumber()));
        });
        return list;
    }

    public static SafeCheckTaskParamDataDTO initData(KeySafetyIndustriesEnum fEnum) {
        SafeCheckTaskParamDataDTO s = new SafeCheckTaskParamDataDTO();
        s.setFields(fEnum.getCode()).setKey(fEnum.getDefaultValue()).setRiskDesc(fEnum.getDesc()).setRiskCode(fEnum.getNumber());
        return s;
    }

    /**
     * 前端传递的参数 如果和默认值不一致并是限期整改的 返回描述信息
     */
    public static List<String> getProblemDesc(List<SafeCheckTaskParamDataDTO> others) {
        List<String> list = new ArrayList<>();
        for (SafeCheckTaskParamDataDTO other : others) {
            KeySafetyIndustriesEnum industriesEnum = getEnumByCode(other.getFields());
            // 判断是否为限期整改
            if (RectificateTimeEnum.isDeadlineRectification(other, industriesEnum.getDefaultValue())) {
                list.add(industriesEnum.getDesc());
            }
        }
        return list;
    }
}
